package org.courierio.jeesite.search;

import org.courierframework.core.search.Searchable;
import org.courierio.jeesite.bean.User;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.Map;

/**
 * @author long.shiyu
 * @since 1.7
 */
public class UserSearch extends Searchable<User> {
    private String username;
    private String cellPhone;
    private Date begin;
    private Date end;

    @Override
    protected void addConditionsAndParameters(Map<String, Object[]> map) {
        if (!StringUtils.isEmpty(username)) {
            map.put("o.username=?1", new Object[]{username});
        }
        if (!StringUtils.isEmpty(cellPhone)) {
            map.put("o.cellPhone=?2", new Object[]{cellPhone});
        }
        if (begin != null && end != null) {
            map.put("o.createDate>?3 and o.createDate <?4", new Object[]{begin, end});
        }
        map.put("order by o.id desc", null);
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getCellPhone() {
        return cellPhone;
    }

    public void setCellPhone(String cellPhone) {
        this.cellPhone = cellPhone;
    }

    public Date getBegin() {
        return begin;
    }

    public void setBegin(Date begin) {
        this.begin = begin;
    }

    public Date getEnd() {
        return end;
    }

    public void setEnd(Date end) {
        this.end = end;
    }
}
